#!/bin/sh
cd /private/var/mobile/Library/Preferences/XBMC/addons/script.atv2updatenighlybuild
echo Deleting old nightly install file
rm xbmc-.*-.*-master-atv2.deb
xbmcdir=http://mirrors.xbmc.org/nightlies/darwin/atv2
wget -q $xbmcdir /private/var/mobile/Library/Preferences/XBMC/addons/script.atv2updatenighlybuild
xbmcdeb=$(cat index.html | gawk 'match($0, ">(xbmc-.*-.*-master-atv2.deb)<", a) {print a[1]}' | head -n 1)
rm /private/var/mobile/Library/Preferences/XBMC/addons/script.atv2updatenighlybuild/index.html
echo Downloading latest nighly build
wget $xbmcdir/$xbmcdeb /private/var/mobile/Library/Preferences/XBMC/addons/script.atv2updatenighlybuild
echo Installing...
dpkg -i /private/var/mobile/Library/Preferences/XBMC/addons/script.atv2updatenighlybuild/$xbmcdeb
rm /private/var/mobile/Library/Preferences/XBMC/addons/script.atv2updatenighlybuild/$xbmcdeb